// 全局请求封装

import env from './env.js'
 
// 需要修改token，和根据实际修改请求头
export default (url, method, contentType, params) => {
	// 获取本地token
	const token = uni.getStorageSync('token')
	
	let header = {}
	header['content-type'] = contentType
	header['deviceType'] = 'weChat'
	header['appVersion'] = '3.0.0'
	if(token) {
		header['token'] = token
	}
	
	return new Promise((resolve, reject) => {
		uni.request({
			header: header,
			url: env.baseUrl + url,
			method: method,
			data: params || {},
			success(response) {
				const res = response
				resolve(res)
			},
			fail(err) {
				reject(err)
			},
			complete() {
 
			}
		});
	}).catch((e) => {});
};